package com.dcshop.demo.controller;

import com.github.ontio.OntSdk;
import com.github.ontio.account.Account;

/**
 * 通用方法
 */
public abstract class AbsController {

    //平台测试账号、密码
    public static final String PLT_ADDRESS = "AQoSxzq3nnkcyby9sTmvjLEDDZrVDxU796";
    public static final String PLT_PASSWORD = "123456";
    public static final String SERVER_ADDRESS = "http://127.0.0.1";
    public static final String SERVER_PORT = "20334";

    /**
     * ontsdk初始化，demo测试用
     *
     * @return
     * @throws Exception
     */
    public OntSdk getOntSdk() throws Exception {
        String restUrl = SERVER_ADDRESS + ":" + SERVER_PORT;
        OntSdk wm = OntSdk.getInstance();
        wm.setRestful(restUrl);
        wm.setDefaultConnect(wm.getRestful());
        wm.openWalletFile("wallet4.dat");
        return wm;
    }

    /**
     * 平台公共账号，支付本体上操作gas
     *
     * @param ontSdk
     * @return
     * @throws Exception
     */
    public Account getPlatformAccount(OntSdk ontSdk) throws Exception {
        //准备前提，先要有PLT_ADDRESS钱包账号，并且，转点币到这个地址
        return ontSdk.getWalletMgr().getAccount(PLT_ADDRESS, PLT_PASSWORD);
    }


    /**
     * 从数据库查询映射关系
     *
     * @param username
     * @return
     */
    public String queryOntidByUsename(String username) {

        //TODO from db

        String ontid = username;

        return ontid;
    }


}
